package com.sumainfor.pc.gmio.service.impl;

import cn.afterturn.easypoi.entity.vo.MapExcelConstants;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.generator.config.IFileCreate;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.sumainfor.common.easypoiExcel.utils.ExcelStyleUtil;
import com.sumainfor.common.exception.TCException;
import com.sumainfor.common.util.CustomMap;
import com.sumainfor.common.util.FieldCheckUtil;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.util.ObjectUtil;
import com.sumainfor.common.utlis.ConvertDateTime;
import com.sumainfor.pc.gmio.dao.StatementServiceMapper;
import com.sumainfor.pc.gmio.feign.BasePcEpcFeign;
import com.sumainfor.pc.gmio.feign.BasePcMktFeign;
import com.sumainfor.pc.gmio.feign.ZuulFeign.ZuulFeign;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.ModelMap;

import javax.print.DocFlavor;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

import static com.sumainfor.common.util.ObjectUtil.converStringForArray;

/**
 * @Author Eddy·Chen
 * @Email 835033913@qq.com
 * @Create 2019-06-19 15:36
 */
@Service
@Transactional(rollbackFor = Exception.class)
@Slf4j
@SuppressWarnings("all")
public class StatementServiceImpl {

    @Autowired
    private StatementServiceMapper mapper;

    @Autowired
    private BasePcMktFeign mktFeign;

    @Autowired
    private BasePcEpcFeign epcFeign;

    @Autowired
    private ZuulFeign zuulFeign;

    /**
     * 杂费收款数据(zc)
     */
public List<Map<String,Object>> getIncidentalsForGetTabless(Map<String,Object> params){

    List<String> HouInfoIdOneList = new ArrayList<>();
    List<Map<String,Object>> getHouBillList = mapper.getHouBillList();
    if (getHouBillList.size()>0&&getHouBillList!=null) {
        for (Map<String, Object> map2 : getHouBillList) {
            HouInfoIdOneList.add(map2.get("HouInfoId").toString());
        }
    }

    List<String> HouInfoIdTwoList = new ArrayList<>();
    List<Map<String,Object>> getHouIncidList = mktFeign.getHouIncid(params);
    if (getHouIncidList.size()>0){
        for (Map<String,Object> map1:getHouIncidList){
            HouInfoIdTwoList.add(map1.get("HouInfoId").toString());
        }
    }
 HouInfoIdTwoList.retainAll(HouInfoIdOneList);//列表展示的房源数据

    //根据房源集合编号和时间间隔查询房源数据

    List<Map<String,Object>> JieGuoList = new ArrayList<>();

if (HouInfoIdTwoList.size()>0){
    params.put("HouInfoIdTwoList",HouInfoIdTwoList);
    JieGuoList = mapper.getHouJieGuolist(params);
    for (Map<String,Object> mapOne:JieGuoList){
        String StringHou = mapOne.get("HouInfoId").toString();
        mapOne.put("deposit",mapper.getHouInfoBillSum(CustomMap.create("HouInfoId", StringHou)
                .put("BiType", 1)
                .put("DepositType",2)
                .put("startTime",params.get("startTime"))
                .put("endTime",params.get("endTime"))
        ).get("PayMoneySum"));//押金
        mapOne.put("electricity",mapper.getHouInfoBillSum(CustomMap.create("HouInfoId", StringHou)
                .put("BiType", 2)
                .put("PubType",2)
                .put("startTime",params.get("startTime"))
                .put("endTime",params.get("endTime"))
        ).get("PayMoneySum"));//电费
        mapOne.put("waterMoney",mapper.getHouInfoBillSum(CustomMap.create("HouInfoId", StringHou)
                .put("BiType", 2)
                .put("PubType",1)
                .put("startTime",params.get("startTime"))
                .put("endTime",params.get("endTime"))
        ).get("PayMoneySum"));//水费
        mapOne.put("gasMoney",mapper.getHouInfoBillSum(CustomMap.create("HouInfoId", StringHou)
                .put("BiType", 2)
                .put("PubType",3)
                .put("startTime",params.get("startTime"))
                .put("endTime",params.get("endTime"))
        ).get("PayMoneySum"));//燃气
        mapOne.put("netMoney",mapper.getHouInfoBillSum(CustomMap.create("HouInfoId", StringHou)
                .put("BiType", 2)
                .put("PubType",4)
                .put("startTime",params.get("startTime"))
                .put("endTime",params.get("endTime"))
        ).get("PayMoneySum"));//宽带
        mapOne.put("maintainMoney",mapper.getHouInfoBillSum(CustomMap.create("HouInfoId", StringHou)
                .put("BiType", 3)
                .put("startTime",params.get("startTime"))
                .put("endTime",params.get("endTime"))
        ).get("PayMoneySum"));//维修
        mapOne.put("linshiMoney",mapper.getHouInfoBillSum(CustomMap.create("HouInfoId", StringHou)
                .put("BiType", 4)
                .put("startTime",params.get("startTime"))
                .put("endTime",params.get("endTime"))
        ).get("PayMoneySum"));//临时
        mapOne.put("qiteMoney",mapper.getHouInfoBillSum(CustomMap.create("HouInfoId", StringHou)
                .put("BiType", 5)
                .put("startTime",params.get("startTime"))
                .put("endTime",params.get("endTime"))
        ).get("PayMoneySum"));//其他
        mapOne.put("tuizuMoney",mapper.getHouInfoBillSum(CustomMap.create("HouInfoId", StringHou)
                .put("BiType", 6)
                .put("startTime",params.get("startTime"))
                .put("endTime",params.get("endTime"))
        ).get("PayMoneySum"));//退租
        mapOne.put("yejianMoney",mapper.getHouInfoBillSum(CustomMap.create("HouInfoId", StringHou)
                .put("BiType", 7)
                .put("startTime",params.get("startTime"))
                .put("endTime",params.get("endTime"))
        ).get("PayMoneySum"));//夜间开门
        mapOne.put("zhinengMoney",mapper.getHouInfoBillSum(CustomMap.create("HouInfoId", StringHou)
                .put("BiType", 8)
                .put("startTime",params.get("startTime"))
                .put("endTime",params.get("endTime"))
        ).get("PayMoneySum"));//智能电表
        mapOne.put("allSum",mapper.getHouInfoBillSum(CustomMap.create("HouInfoId", StringHou)
                .put("hejiType", 1)
                .put("startTime",params.get("startTime"))
                .put("endTime",params.get("endTime"))
        ).get("PayMoneySum"));//合计

        List<Map<String,Object>> getXinxiHou = mktFeign.getHouIncid(mapOne);//根据房源编号查询房源信息
        mapOne.putAll(getXinxiHou.get(0));
        mapOne.put("area_id",mapOne.get("CorId"));//公司编号
        mapOne.put("dept_id",mapOne.get("MiId"));//服务中心编号
        JsonResult zuulResult = zuulFeign.getAreaid(mapOne);
        Map<String,Object> zuulAreaMap = (Map<String, Object>) zuulResult.get("result");
        mapOne.putAll(zuulAreaMap);;
        mapOne.putAll(zuulFeign.getdeptname(mapOne));
    }
}

//依次添加公司及服务中心
    //获取公司名称


    //获取服务中心名称




    return JieGuoList;
}




    public Integer getIncidentalsForGetTablessCount(Map<String,Object> params){

        Integer count = new Integer("0");
        List<String> HouInfoIdOneList = new ArrayList<>();
        List<Map<String,Object>> getHouBillList = mapper.getHouBillList();
        if (getHouBillList.size()>0&&getHouBillList!=null) {
            for (Map<String, Object> map2 : getHouBillList) {
                HouInfoIdOneList.add(map2.get("HouInfoId").toString());
            }
        }
        List<String> HouInfoIdTwoList = new ArrayList<>();
        List<Map<String,Object>> getHouIncidList = mktFeign.getHouIncid(params);
        if (getHouIncidList.size()>0){
            for (Map<String,Object> map1:getHouIncidList){
                HouInfoIdTwoList.add(map1.get("HouInfoId").toString());
            }
        }
        HouInfoIdTwoList.retainAll(HouInfoIdOneList);//列表展示的房源数据

        if (HouInfoIdTwoList.size()>0){
            params.put("HouInfoIdTwoList",HouInfoIdTwoList);
            count = mapper.getHouJieGuolistCount(params);
        }

return count;
    }

    /**
     * 杂费付款
     * @param params
     * @return
     */
    public List<Map<String,Object>> getIncidentalsForOutss(Map<String,Object> params){

    List<String> HouInfoIdOneList = new ArrayList<>();
    List<Map<String,Object>> getHouBillList = mapper.getHouBillOutList();
        if (getHouBillList.size()>0&&getHouBillList!=null) {
            for (Map<String, Object> map2 : getHouBillList) {
                HouInfoIdOneList.add(map2.get("HouInfoId").toString());
            }
        }

    List<String> HouInfoIdTwoList = new ArrayList<>();
    List<Map<String,Object>> getHouIncidList = mktFeign.getHouIncid(params);
    if (getHouIncidList.size()>0){
        for (Map<String,Object> map1:getHouIncidList){
            HouInfoIdTwoList.add(map1.get("HouInfoId").toString());
        }
    }
    HouInfoIdTwoList.retainAll(HouInfoIdOneList);//列表展示的房源数据

    //根据房源集合编号和时间间隔查询房源数据

    List<Map<String,Object>> JieGuoList = new ArrayList<>();

    if (HouInfoIdTwoList.size()>0){
        params.put("HouInfoIdTwoList",HouInfoIdTwoList);
        JieGuoList = mapper.getHouJieGuoBillOutlist(params);
        for (Map<String,Object> mapOne:JieGuoList){
            String StringHou = mapOne.get("HouInfoId").toString();
            mapOne.put("gongyingshang",mapper.getHouInfoBillOutSum(CustomMap.create("HouInfoId", StringHou)
                    .put("BiOutType", 2)
                    .put("startTime",params.get("startTime"))
                    .put("endTime",params.get("endTime"))
            ).get("PayMoneySum"));//供应商
            mapOne.put("tuizu",mapper.getHouInfoBillOutSum(CustomMap.create("HouInfoId", StringHou)
                    .put("BiOutType", 3)
                    .put("startTime",params.get("startTime"))
                    .put("endTime",params.get("endTime"))
            ).get("PayMoneySum"));//退租
            mapOne.put("waterMoney",mapper.getHouInfoBillOutSum(CustomMap.create("HouInfoId", StringHou)
                    .put("BiOutType", 4)
                    .put("PubType",1)
                    .put("startTime",params.get("startTime"))
                    .put("endTime",params.get("endTime"))
            ).get("PayMoneySum"));//水费
            mapOne.put("eleMoney",mapper.getHouInfoBillOutSum(CustomMap.create("HouInfoId", StringHou)
                    .put("BiOutType", 4)
                    .put("PubType",2)
                    .put("startTime",params.get("startTime"))
                    .put("endTime",params.get("endTime"))
            ).get("PayMoneySum"));//电
            mapOne.put("gasMoney",mapper.getHouInfoBillOutSum(CustomMap.create("HouInfoId", StringHou)
                    .put("BiOutType", 4)
                    .put("PubType",3)
                    .put("startTime",params.get("startTime"))
                    .put("endTime",params.get("endTime"))
            ).get("PayMoneySum"));//燃
            mapOne.put("kuanMoney",mapper.getHouInfoBillOutSum(CustomMap.create("HouInfoId", StringHou)
                    .put("BiOutType", 4)
                    .put("PubType", 3)
                    .put("startTime",params.get("startTime"))
                    .put("endTime",params.get("endTime"))
            ).get("PayMoneySum"));//宽
            mapOne.put("yezhuwei",mapper.getHouInfoBillOutSum(CustomMap.create("HouInfoId", StringHou)
                    .put("BiOutType", 6)
                    .put("startTime",params.get("startTime"))
                    .put("endTime",params.get("endTime"))
            ).get("PayMoneySum"));//业主违
            mapOne.put("allSum",mapper.getHouInfoBillSum(CustomMap.create("HouInfoId", StringHou)
                    .put("hejiType", 1)
                    .put("startTime",params.get("startTime"))
                    .put("endTime",params.get("endTime"))
            ).get("PayMoneySum"));//合计

            List<Map<String,Object>> getXinxiHou = mktFeign.getHouIncid(mapOne);//根据房源编号查询房源信息
            mapOne.putAll(getXinxiHou.get(0));
            mapOne.put("area_id",mapOne.get("CorId"));//公司编号
            mapOne.put("dept_id",mapOne.get("MiId"));//服务中心编号
            JsonResult zuulResult = zuulFeign.getAreaid(mapOne);
            Map<String,Object> zuulAreaMap = (Map<String, Object>) zuulResult.get("result");
            mapOne.putAll(zuulAreaMap);;
            mapOne.putAll(zuulFeign.getdeptname(mapOne));
        }
    }

    return JieGuoList;

}




    public Integer getIncidentalsForOutssCount(Map<String,Object> params){

        Integer count = new Integer("0");
        List<String> HouInfoIdOneList = new ArrayList<>();
        List<Map<String,Object>> getHouBillList = mapper.getHouBillOutList();
        if (getHouBillList.size()>0&&getHouBillList!=null) {
            for (Map<String, Object> map2 : getHouBillList) {
                HouInfoIdOneList.add(map2.get("HouInfoId").toString());
            }
        }

        List<String> HouInfoIdTwoList = new ArrayList<>();
        List<Map<String,Object>> getHouIncidList = mktFeign.getHouIncid(params);
        if (getHouIncidList.size()>0){
            for (Map<String,Object> map1:getHouIncidList){
                HouInfoIdTwoList.add(map1.get("HouInfoId").toString());
            }
        }
        HouInfoIdTwoList.retainAll(HouInfoIdOneList);//列表展示的房源数据

        if (HouInfoIdTwoList.size()>0){
            params.put("HouInfoIdTwoList",HouInfoIdTwoList);
            count = mapper.getHouJieGuoBillOutlistCount(params);
        }

        return count;
    }



















    /**
     * 获取杂费收款表格数据
     *
     * @param page
     * @param params
     * @return
     */
    public Page<Map<String, Object>> getIncidentalsForGet(Page page, Map<String, Object> params) {

        //存储的是房源详表编号集合
        List<String> hinfoIds = Lists.newArrayList();
        //存储的是房源主集合
        List<String> hIds = Lists.newArrayList();

        params.put("hInfoIds", hinfoIds);
        params.put("hIds", hIds);

        //判断是否传入时间为空
        if (!FieldCheckUtil.isMapFieldNotNull(params, "startTime", "endTime")) {
            //如果为空那么取当年的数据范围
            params.put("startTime", DateTime.now().dayOfYear().withMinimumValue().toString("yyyy-MM-dd"));
            params.put("endTime", DateTime.now().dayOfYear().withMaximumValue().toString("yyyy-MM-dd"));
        }

        //获取房源详表编号
        String formHInfoId = MapUtils.getString(params, "formHInfoId");
        //获取房源主编号
        String formHId = MapUtils.getString(params, "formHId");
        //获取项目编号
        String comId = MapUtils.getString(params, "comId");
        //获取服务中心编号
        String centerId = MapUtils.getString(params, "centerId");
        //获取所属公司编号
        String areaId = MapUtils.getString(params, "areaId");

        //判断如果选择的是室号
        if (StringUtils.isNotBlank(formHInfoId)) {
            //如果不为空
            hinfoIds.addAll(converStringForArray(formHInfoId));
        } else if (StringUtils.isNotBlank(formHId)) {
            hIds.addAll(converStringForArray(formHId));
        } else if (StringUtils.isNotBlank(comId)) {
            //查询这个项目下所有的房源匹配过滤
            Set<String> houId = mapper.selectHousingIdList(params).stream().map(item -> MapUtils.getString(item, "HouId")).collect(Collectors.toSet());
            if (CollectionUtils.isEmpty(houId)) {
                return page;
            }
            //查询房源的所属项目编号
            List<String> comIdList = converStringForArray(comId);
            List<String> hList = Lists.newArrayList();
            for (String s : comIdList) {
                JsonResult<List<String>> result = mktFeign.selectComIdByHId(CustomMap.create("hIds", houId)
                        .put("val", s)
                        .put("col", "hmain.HouId")
                        .put("where", "community.ComId")
                );
                if (!result.isSuccess()) {
                    throw new TCException("异常:" + result.getErrorMessage());
                }
                hList.addAll(result.getResult());
            }
            if (CollectionUtils.isEmpty(hList)) {
                return page;
            }
            hIds.addAll(hList);
        } else if (StringUtils.isNotBlank(centerId)) {
            Set<String> houId = mapper.selectHousingIdList(params).stream().map(item -> MapUtils.getString(item, "HouId")).collect(Collectors.toSet());
            if (CollectionUtils.isEmpty(houId)) {
                return page;
            }
            List<String> centerIdList = converStringForArray(centerId);
            List<String> hList = Lists.newArrayList();
            //查询房源的编号根据服务中心编号
            for (String id : centerIdList) {
                JsonResult<List<String>> result = mktFeign.selectComIdByHId(CustomMap.create("hIds", houId)
                        .put("val", id)
                        .put("col", "hmain.HouId")
                        .put("where", "community.MiId")
                );
                if (!result.isSuccess()) {
                    throw new TCException("异常:" + result.getErrorMessage());
                }
                hList.addAll(result.getResult());
            }
            if (CollectionUtils.isEmpty(hList)) {
                return page;
            }
            hIds.addAll(hList);
        } else if (StringUtils.isNotBlank(areaId)) {
            Set<String> houId = mapper.selectHousingIdList(params).stream().map(item -> MapUtils.getString(item, "HouId")).collect(Collectors.toSet());
            if (CollectionUtils.isEmpty(houId)) {
                return page;
            }

            List<String> areaIdList = converStringForArray(areaId);
            List<String> hList = Lists.newArrayList();
            //查询房源的编号根据服务中心编号
            for (String id : areaIdList) {
                JsonResult<List<String>> result = mktFeign.selectComIdByHId(CustomMap.create("hIds", houId)
                        .put("val", id)
                        .put("col", "hmain.HouId")
                        .put("where", "hmain.CorId")
                );
                if (!result.isSuccess()) {
                    throw new TCException("异常:" + result.getErrorMessage());
                }
                hList.addAll(result.getResult());
            }
            if (CollectionUtils.isEmpty(hList)) {
                return page;
            }
            hIds.addAll(hList);
        }
        List<Map<String, Object>> dataList = mapper.selectIncidentalsForGet(params);

        if (CollectionUtils.isEmpty(dataList)) {
            return page;
        }

        //获取房源信息根据主编号
        Set<String> hIdSets = dataList.stream().map(item -> MapUtils.getString(item, "HouId")).collect(Collectors.toSet());

        JsonResult<List<Map<String, Object>>> detailJson = mktFeign.selectHousingDetailByArray(hIdSets);
        if (!detailJson.isSuccess()) {
            throw new TCException("错误：" + detailJson.getErrorMessage());
        }

        //查找房间号 根据房源配置编号
        Set<String> conIds = dataList.stream().filter(fItem -> MapUtils.getInteger(fItem, "BiType").equals(3)).map(conItem -> MapUtils.getString(conItem, "HouCon")).collect(Collectors.toSet());
        List<Map<String, Object>> roomList = null;
        if (CollectionUtils.isNotEmpty(conIds)) {
            JsonResult<List<Map<String, Object>>> roomJson = mktFeign.getHousingRoom(conIds);
            if (!roomJson.isSuccess()) {
                throw new TCException("错误：" + roomJson.getErrorMessage());
            }
            roomList = roomJson.getResult();
        }

        //按照收款日期组合起来  1.获取需要的数据
        Map<String, List<Map<String, Object>>> eqHou = Maps.newHashMap();

        for (Map<String, Object> map : dataList) {
            for (Map<String, Object> detailItem : detailJson.getResult()) {
                if (Objects.equals(MapUtils.getString(map, "HouId"), MapUtils.getString(detailItem, "HouId"))) {
                    map.putAll(detailItem);
                    break;
                }
            }
            //设置房间号
            if (MapUtils.getInteger(map, "BiType").equals(3)) {
                if (CollectionUtils.isEmpty(roomList)) {
                    throw new TCException("数据错误");
                }
                for (Map<String, Object> roomMap : roomList) {
                    if (Objects.equals(MapUtils.getString(map, "HouCon"), MapUtils.getString(roomMap, "HouCon"))) {
                        String room = MapUtils.getString(roomMap, "HouConId").substring(MapUtils.getString(roomMap, "HouConId").length() - 1, MapUtils.getString(roomMap, "HouConId").length());
                        map.put("room", room);
                        break;
                    }
                }
            } else {
                String room = MapUtils.getString(map, "HouInfoId").substring(MapUtils.getString(map, "HouInfoId").length() - 1, MapUtils.getString(map, "HouInfoId").length());
                map.put("room", room);
            }
            //分组操作
            //1. 先把相同的房源匹配一起
            String keyName = String.format("%s%s%s%s%s%s", MapUtils.getString(map, "areaName")
                    , MapUtils.getString(map, "centerName"), MapUtils.getString(map, "ComName")
                    , MapUtils.getString(map, "Building"), MapUtils.getString(map, "Room"), MapUtils.getString(map, "room")
            );
            List<Map<String, Object>> itemList;
            if (eqHou.containsKey(keyName)) {
                itemList = eqHou.get(keyName);
            } else {
                itemList = Lists.newArrayList();
                eqHou.put(keyName, itemList);
            }
            itemList.add(map);
        }

        List<Map<String, Object>> resultList = Lists.newArrayList();
        //2.然后根据相同的时间进行组合
        for (Map.Entry<String, List<Map<String, Object>>> entry : eqHou.entrySet()) {

            Map<String, List<Map<String, Object>>> timeMap = Maps.newHashMap();
            for (Map<String, Object> item : entry.getValue()) {
                //获取时间
                String time = MapUtils.getString(item, "BiGenerated");
                List<Map<String, Object>> timeChild;
                if (timeMap.containsKey(time)) {
                    timeChild = timeMap.get(time);
                } else {
                    timeChild = Lists.newArrayList();
                    timeMap.put(time, timeChild);
                }
                timeChild.add(item);
            }
            //把分组好的时间进行组合成一个数据 Map对象
            for (Map.Entry<String, List<Map<String, Object>>> timeItem : timeMap.entrySet()) {
                Map<String, Object> dataItem = Maps.newHashMap();
                dataItem.putAll(timeItem.getValue().get(0));
                dataItem.remove("Money");
                dataItem.remove("payType");
                dataItem.remove("HouId");
                dataItem.remove("HouInfoId");
                dataItem.remove("orderType");
                dataItem.remove("BiType");
                dataItem.remove("HouCon");

                String room = MapUtils.getString(dataItem, "room");
                if (room.equals("Z")) {
                    dataItem.put("room", "整租");
                } else {
                    dataItem.put("room", "房间" + room);
                }

                //添加金额
                //押金
                dataItem.put("deposit", new BigDecimal(0));
                //电费
                dataItem.put("electricity", new BigDecimal(0));
                //水费
                dataItem.put("waterMoney", new BigDecimal(0));
                //燃气费
                dataItem.put("gasMoney", new BigDecimal(0));
                //网络费
                dataItem.put("netMoney", new BigDecimal(0));
                //夜间开门费
                dataItem.put("openMoney", new BigDecimal(0));
                //转租服务费
                dataItem.put("subletMoney", new BigDecimal(0));
                //换房服务费
                dataItem.put("roomChangeMoney", new BigDecimal(0));
                //维修费
                dataItem.put("maintainMoney", new BigDecimal(0));
                //其他费用
                dataItem.put("otherMoney", new BigDecimal(0));
                //智能电表费用
                dataItem.put("elAutoMoney", new BigDecimal(0));

                //转账类型
                dataItem.put("payType", "");

                //合计的费用
                BigDecimal allSum = new BigDecimal("0");
                //杂费的合计
                BigDecimal otherSum;

                for (Map<String, Object> map : timeItem.getValue()) {
                    BigDecimal money = ObjectUtil.convertBigDecimal(map.get("Money"), "0");
                    allSum = allSum.add(money);
                    Integer orderType = MapUtils.getIntValue(map, "orderType");
                    switch (orderType) {
                        case 1:
                            dataItem.put("waterMoney", ((BigDecimal) (dataItem.get("waterMoney"))).add(money));
                            break;
                        case 2:
                            dataItem.put("electricity", ((BigDecimal) (dataItem.get("electricity"))).add(money));
                            break;
                        case 3:
                            dataItem.put("gasMoney", ((BigDecimal) (dataItem.get("gasMoney"))).add(money));
                            break;
                        case 4:
                            //水电押金
                            dataItem.put("deposit", ((BigDecimal) (dataItem.get("deposit"))).add(money));
                            dataItem.put("payType", map.get("payType"));
                            break;
                        case 5:
                            dataItem.put("maintainMoney", ((BigDecimal) (dataItem.get("maintainMoney"))).add(money));
                            break;
                        case 6:
                            dataItem.put("otherMoney", ((BigDecimal) (dataItem.get("otherMoney"))).add(money));
                            break;
                        case 7:
                            dataItem.put("subletMoney", ((BigDecimal) (dataItem.get("subletMoney"))).add(money));
                            break;
                        case 8:
                            dataItem.put("roomChangeMoney", ((BigDecimal) (dataItem.get("roomChangeMoney"))).add(money));
                            break;
                        case 9:
                            dataItem.put("openMoney", ((BigDecimal) (dataItem.get("openMoney"))).add(money));
                            break;
                        case 10:
                            dataItem.put("elAutoMoney", ((BigDecimal) (dataItem.get("elAutoMoney"))).add(money));
                            break;
                    }
                }
                //计算合计
                otherSum = allSum.subtract((BigDecimal) MapUtils.getObject(dataItem, "deposit"));
                //总合计
                dataItem.put("allSum", allSum);
                //杂费收款合计
                dataItem.put("otherSum", otherSum);
                //3. 全部放到统一集合中
                resultList.add(dataItem);
            }
        }

        if (page.getSize() < 0) {
            return page.setRecords(resultList);
        }
        //进行分页操作
        page.setTotal(resultList.size());
        if (page.getTotal() <= 0) {
            return page;
        }
        if (page.getTotal() % page.getSize() > 0) {
            page.setPages((page.getTotal() / page.getSize()) + 1);
        } else {
            page.setPages(page.getTotal() / page.getSize());
        }
        List<Map<String, Object>> collect = resultList.stream().skip(((page.getCurrent() - 1) * page.getSize())).limit(page.getSize()).collect(Collectors.toList());
        page.setRecords(collect);
        return page;
    }

//    /**
//     * 导出Excel表格
//     *
//     * @param params
//     */
//    public ModelMap exportIncidentalsForGet(ModelMap modelMap, Map<String, Object> params) {
//        List<Map<String, Object>> dataList = this.getIncidentalsForGet(new Page(1, -1), params).getRecords();
//
//        String startTime = MapUtils.getString(params, "startTime");
//        String endTime = MapUtils.getString(params, "endTime");
//
//        List<ExcelExportEntity> entityList = new ArrayList<>();
//        //构建表格
//        ExportParams exportParams = new ExportParams(String.format("杂费收款统计 %s~%s", startTime, endTime), "杂费收款", ExcelType.XSSF);
//        exportParams.setStyle(ExcelStyleUtil.class);
//        exportParams.setFixedTitle(true);
//
//        entityList.add(new ExcelExportEntity("收款日期", "BiGenerated"));
//        entityList.add(new ExcelExportEntity("公司", "areaName"));
//        entityList.add(new ExcelExportEntity("服务中心", "centerName"));
//        entityList.add(new ExcelExportEntity("小区名称", "ComName"));
//        entityList.add(new ExcelExportEntity("楼号", "Building"));
//        entityList.add(new ExcelExportEntity("房号", "Room"));
//        entityList.add(new ExcelExportEntity("室号", "room"));
//        entityList.add(new ExcelExportEntity("收款方式", "payType"));
//
//        ExcelExportEntity deposit = new ExcelExportEntity("水电押金收入", "deposit");
//        deposit.setStatistics(true);
//        entityList.add(deposit);
//
//        ExcelExportEntity el = new ExcelExportEntity("电费", "electricity");
//        el.setStatistics(true);
//        entityList.add(el);
//
//        ExcelExportEntity water = new ExcelExportEntity("水费", "waterMoney");
//        water.setStatistics(true);
//        entityList.add(water);
//
//        ExcelExportEntity gas = new ExcelExportEntity("煤气费", "gasMoney");
//        gas.setStatistics(true);
//        entityList.add(gas);
//
//        ExcelExportEntity net = new ExcelExportEntity("网络费", "netMoney");
//        net.setStatistics(true);
//        entityList.add(net);
//
//        ExcelExportEntity open = new ExcelExportEntity("夜间开门费", "openMoney");
//        open.setStatistics(true);
//        entityList.add(open);
//
//        ExcelExportEntity sublet = new ExcelExportEntity("转租服务费", "subletMoney");
//        sublet.setStatistics(true);
//        entityList.add(sublet);
//
//        ExcelExportEntity change = new ExcelExportEntity("换房服务费", "roomChangeMoney");
//        change.setStatistics(true);
//        entityList.add(change);
//
//        ExcelExportEntity maintain = new ExcelExportEntity("维修费", "maintainMoney");
//        maintain.setStatistics(true);
//        entityList.add(maintain);
//
//        ExcelExportEntity other = new ExcelExportEntity("其他临时费", "otherMoney");
//        other.setStatistics(true);
//        entityList.add(other);
//
//        ExcelExportEntity otherSum = new ExcelExportEntity("杂费收款合计", "otherSum");
//        otherSum.setStatistics(true);
//        entityList.add(otherSum);
//
//        ExcelExportEntity allSum = new ExcelExportEntity("收款合计", "allSum");
//        allSum.setStatistics(true);
//        entityList.add(allSum);
//
//        for (ExcelExportEntity entity : entityList) {
//            entity.setWidth(15);
//        }
//
//        modelMap.put(MapExcelConstants.MAP_LIST, dataList);
//        modelMap.put(MapExcelConstants.ENTITY_LIST, entityList);
//        modelMap.put(MapExcelConstants.PARAMS, exportParams);
//        modelMap.put(MapExcelConstants.FILE_NAME, String.format("杂费收款统计报表 (%s~%s)", startTime, endTime));
//        return modelMap;
//    }


    /**
     * 导出Excel表格
     *
     * @param params
     */
    public ModelMap exportIncidentalsForGet(ModelMap modelMap, Map<String, Object> params) throws Exception {

        Map<String,Object> dealMap = this.DateDealwith(params);
        //如果为空那么取当年的数据范围
        params.put("startTime", dealMap.get("StartTime"));
        params.put("endTime", dealMap.get("EndTime"));


        List<Map<String, Object>> dataList = this.getIncidentalsForGetTabless(params);


        String startTime = MapUtils.getString(params, "startTime");
        String endTime = MapUtils.getString(params, "endTime");

        List<ExcelExportEntity> entityList = new ArrayList<>();
        //构建表格
        ExportParams exportParams = new ExportParams(String.format("杂费收款统计 %s~%s", startTime, endTime), "杂费收款", ExcelType.XSSF);
        exportParams.setStyle(ExcelStyleUtil.class);
        exportParams.setFixedTitle(true);

       // entityList.add(new ExcelExportEntity("收款日期", "BiGenerated"));
        entityList.add(new ExcelExportEntity("公司", "name"));
        entityList.add(new ExcelExportEntity("服务中心", "deptname"));
        entityList.add(new ExcelExportEntity("小区名称", "ComName"));
        entityList.add(new ExcelExportEntity("楼号", "BuilDing"));
        entityList.add(new ExcelExportEntity("房号", "Room"));
        entityList.add(new ExcelExportEntity("房间号", "cod"));
        //entityList.add(new ExcelExportEntity("收款方式", "payType"));

        ExcelExportEntity deposit = new ExcelExportEntity("水电押金收入", "deposit");
        deposit.setStatistics(true);
        entityList.add(deposit);

        ExcelExportEntity el = new ExcelExportEntity("电费", "electricity");
        el.setStatistics(true);
        entityList.add(el);

        ExcelExportEntity water = new ExcelExportEntity("水费", "waterMoney");
        water.setStatistics(true);
        entityList.add(water);

        ExcelExportEntity gas = new ExcelExportEntity("煤气费", "gasMoney");
        gas.setStatistics(true);
        entityList.add(gas);

        ExcelExportEntity net = new ExcelExportEntity("网络费", "netMoney");
        net.setStatistics(true);
        entityList.add(net);


        ExcelExportEntity weixiu = new ExcelExportEntity("维修", "maintainMoney");
        weixiu.setStatistics(true);
        entityList.add(weixiu);

        ExcelExportEntity linshi = new ExcelExportEntity("临时", "linshiMoney");
        linshi.setStatistics(true);
        entityList.add(linshi);

        ExcelExportEntity qite = new ExcelExportEntity("其他", "qiteMoney");
        qite.setStatistics(true);
        entityList.add(qite);

        ExcelExportEntity tuizu = new ExcelExportEntity("退租", "tuizuMoney");
        tuizu.setStatistics(true);
        entityList.add(tuizu);

        ExcelExportEntity yejian = new ExcelExportEntity("夜间开门费", "yejianMoney");
        yejian.setStatistics(true);
        entityList.add(yejian);

        ExcelExportEntity zhineng = new ExcelExportEntity("智能电表", "zhinengMoney");
        zhineng.setStatistics(true);
        entityList.add(zhineng);



        ExcelExportEntity allSum = new ExcelExportEntity("收款合计", "allSum");
        allSum.setStatistics(true);
        entityList.add(allSum);

        for (ExcelExportEntity entity : entityList) {
            entity.setWidth(15);
        }

        modelMap.put(MapExcelConstants.MAP_LIST, dataList);
        modelMap.put(MapExcelConstants.ENTITY_LIST, entityList);
        modelMap.put(MapExcelConstants.PARAMS, exportParams);
        modelMap.put(MapExcelConstants.FILE_NAME, String.format("杂费收款统计报表 (%s~%s)", startTime, endTime));
        return modelMap;
    }





    /**
     * 功能描述:
     * 时间查询处理
     * 月份定义：上月25日00：00到本月24日00:00
     * 前端。传递2019-01至2019-05
     * 转换之后。应该查询的数据是2019-01-25-2019-05-24之间的数据
     *
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/6/20 15:14
     */
    public Map<String, Object> DateDealwith(Map<String, Object> params)throws Exception {
        Map<String, Object> result = new HashMap<String, Object>();
        //月份开始时间
        String monthStartTime;
        //月份结束时间
        String monthEndTime;
        //如果开始月份为空，默认当年1月
        if(!FieldCheckUtil.isMapFieldNotNull(params,new String[]{"startTime"})){
            DateTime date = ConvertDateTime.dateFormatStrToTime("yyyy-MM",String.valueOf(ConvertDateTime.getCurrentDateElement(1))+"-01");
            monthStartTime= date.toString("yyyy-MM");
        }else{
            DateTime date =ConvertDateTime.dateFormatStrToTime("yyyy-MM",params.get("startTime").toString());
            monthStartTime= date.toString("yyyy-MM");
        }
        //如果结束月份为空，默认当年12月
        if(!FieldCheckUtil.isMapFieldNotNull(params,new String[]{"endTime"})){
            DateTime date = ConvertDateTime.dateFormatStrToTime("yyyy-MM",String.valueOf(ConvertDateTime.getCurrentDateElement(1))+"-12");
            monthEndTime=date.toString("yyyy-MM");
        }else{
            DateTime date =ConvertDateTime.dateFormatStrToTime("yyyy-MM",params.get("endTime").toString());
            monthEndTime=date.toString("yyyy-MM");
        }

        result.put("StartTime", monthStartTime + "-26");
        result.put("EndTime", monthEndTime + "-25");
        return result;
    }















    /**
     * 获取杂费付款表格数据
     *
     * @param page
     * @param params
     * @return
     */
    public Page<Map<String, Object>> getIncidentalsForOut(Page page, Map<String, Object> params) {
        //存储的是房源详表编号集合
        List<String> hinfoIds = Lists.newArrayList();
        //存储的是房源主集合
        List<String> hIds = Lists.newArrayList();

        params.put("hInfoIds", hinfoIds);
        params.put("hIds", hIds);

        //判断是否传入时间为空
        if (!FieldCheckUtil.isMapFieldNotNull(params, "startTime", "endTime")) {
            //如果为空那么取当年的数据范围
            params.put("startTime", DateTime.now().dayOfYear().withMinimumValue().toString("yyyy-MM-dd"));
            params.put("endTime", DateTime.now().dayOfYear().withMaximumValue().toString("yyyy-MM-dd"));
        }

        //获取房源详表编号
        String formHInfoId = MapUtils.getString(params, "formHInfoId");
        //获取房源主编号
        String formHId = MapUtils.getString(params, "formHId");
        //获取项目编号
        String comId = MapUtils.getString(params, "comId");
        //获取服务中心编号
        String centerId = MapUtils.getString(params, "centerId");
        //获取所属公司编号
        String areaId = MapUtils.getString(params, "areaId");

        //判断如果选择的是室号
        if (StringUtils.isNotBlank(formHInfoId)) {
            //如果不为空
            hinfoIds.addAll(converStringForArray(formHInfoId));
        } else if (StringUtils.isNotBlank(formHId)) {
            hIds.add(formHId);
        } else if (StringUtils.isNotBlank(comId)) {
            //查询这个项目下所有的房源匹配过滤
            Set<String> houId = mapper.selectHousingIdListForOut(params).stream().map(item -> MapUtils.getString(item, "HouId")).collect(Collectors.toSet());
            if (CollectionUtils.isEmpty(houId)) {
                return page;
            }
            //查询房源的所属项目编号
            List<String> comIdList = converStringForArray(comId);
            List<String> hList = Lists.newArrayList();
            for (String s : comIdList) {
                JsonResult<List<String>> result = mktFeign.selectComIdByHId(CustomMap.create("hIds", houId)
                        .put("val", s)
                        .put("col", "hmain.HouId")
                        .put("where", "community.ComId")
                );
                if (!result.isSuccess()) {
                    throw new TCException("异常:" + result.getErrorMessage());
                }
                hList.addAll(result.getResult());
            }
            if (CollectionUtils.isEmpty(hList)) {
                return page;
            }
            hIds.addAll(hList);
        } else if (StringUtils.isNotBlank(centerId)) {
            Set<String> houId = mapper.selectHousingIdListForOut(params).stream().map(item -> MapUtils.getString(item, "HouId")).collect(Collectors.toSet());
            if (CollectionUtils.isEmpty(houId)) {
                return page;
            }
            List<String> centerIdList = converStringForArray(centerId);
            List<String> hList = Lists.newArrayList();
            //查询房源的编号根据服务中心编号
            for (String id : centerIdList) {
                JsonResult<List<String>> result = mktFeign.selectComIdByHId(CustomMap.create("hIds", houId)
                        .put("val", id)
                        .put("col", "hmain.HouId")
                        .put("where", "community.MiId")
                );
                if (!result.isSuccess()) {
                    throw new TCException("异常:" + result.getErrorMessage());
                }
                hList.addAll(result.getResult());
            }
            if (CollectionUtils.isEmpty(hList)) {
                return page;
            }
            hIds.addAll(hList);
        } else if (StringUtils.isNotBlank(areaId)) {
            Set<String> houId = mapper.selectHousingIdListForOut(params).stream().map(item -> MapUtils.getString(item, "HouId")).collect(Collectors.toSet());
            if (CollectionUtils.isEmpty(houId)) {
                return page;
            }

            List<String> areaIdList = converStringForArray(areaId);
            List<String> hList = Lists.newArrayList();
            //查询房源的编号根据服务中心编号
            for (String id : areaIdList) {
                JsonResult<List<String>> result = mktFeign.selectComIdByHId(CustomMap.create("hIds", houId)
                        .put("val", id)
                        .put("col", "hmain.HouId")
                        .put("where", "hmain.CorId")
                );
                if (!result.isSuccess()) {
                    throw new TCException("异常:" + result.getErrorMessage());
                }
                hList.addAll(result.getResult());
            }
            if (CollectionUtils.isEmpty(hList)) {
                return page;
            }
            hIds.addAll(hList);
        }

        List<Map<String, Object>> dataList = mapper.selectIncidentalsForOut(params);
        if (CollectionUtils.isEmpty(dataList)) {
            return page;
        }
        //获取房源信息根据主编号
        Set<String> hIdSets = dataList.stream().map(item -> MapUtils.getString(item, "HouId")).collect(Collectors.toSet());

        JsonResult<List<Map<String, Object>>> detailJson = mktFeign.selectHousingDetailByArray(hIdSets);
        if (!detailJson.isSuccess()) {
            throw new TCException("错误：" + detailJson.getErrorMessage());
        }
        //按照收款日期组合起来  1.获取需要的数据
        Map<String, List<Map<String, Object>>> eqHou = Maps.newHashMap();

        for (Map<String, Object> map : dataList) {
            for (Map<String, Object> detailItem : detailJson.getResult()) {
                if (Objects.equals(MapUtils.getString(map, "HouId"), MapUtils.getString(detailItem, "HouId"))) {
                    map.putAll(detailItem);
                    break;
                }
            }
            //设置房间号
            String room = MapUtils.getString(map, "HouInfoId").substring(MapUtils.getString(map, "HouInfoId").length() - 1, MapUtils.getString(map, "HouInfoId").length());
            map.put("room", room);
            //分组操作
            //1. 先把相同的房源匹配一起
            String keyName = String.format("%s%s%s%s%s%s", MapUtils.getString(map, "areaName")
                    , MapUtils.getString(map, "centerName"), MapUtils.getString(map, "ComName")
                    , MapUtils.getString(map, "Building"), MapUtils.getString(map, "Room"), MapUtils.getString(map, "room")
            );
            List<Map<String, Object>> itemList;
            if (eqHou.containsKey(keyName)) {
                itemList = eqHou.get(keyName);
            } else {
                itemList = Lists.newArrayList();
                eqHou.put(keyName, itemList);
            }
            itemList.add(map);
        }

        List<Map<String, Object>> resultList = Lists.newArrayList();
        //2.然后根据相同的时间进行组合
        for (Map.Entry<String, List<Map<String, Object>>> entry : eqHou.entrySet()) {

            Map<String, List<Map<String, Object>>> timeMap = Maps.newHashMap();
            for (Map<String, Object> item : entry.getValue()) {
                //获取时间
                String time = MapUtils.getString(item, "BiGenerated");
                List<Map<String, Object>> timeChild;
                if (timeMap.containsKey(time)) {
                    timeChild = timeMap.get(time);
                } else {
                    timeChild = Lists.newArrayList();
                    timeMap.put(time, timeChild);
                }
                timeChild.add(item);
            }
            //把分组好的时间进行组合成一个数据 Map对象
            for (Map.Entry<String, List<Map<String, Object>>> timeItem : timeMap.entrySet()) {
                Map<String, Object> dataItem = Maps.newHashMap();
                dataItem.putAll(timeItem.getValue().get(0));
                dataItem.remove("BiMoney");
                dataItem.remove("HouId");
                dataItem.remove("HouInfoId");

                String room = MapUtils.getString(dataItem, "room");
                if (room.equals("Z")) {
                    dataItem.put("room", "整租");
                } else {
                    dataItem.put("room", "房间" + room);
                }

                //添加金额
                //电费
                dataItem.put("electricity", new BigDecimal(0));
                //水费
                dataItem.put("waterMoney", new BigDecimal(0));
                //燃气费
                dataItem.put("gasMoney", new BigDecimal(0));
                //网络费
                dataItem.put("netMoney", new BigDecimal(0));

                //合计的费用
                BigDecimal allSum = new BigDecimal("0");

                for (Map<String, Object> map : timeItem.getValue()) {
                    BigDecimal money = ObjectUtil.convertBigDecimal(map.get("BiMoney"), "0");
                    allSum = allSum.add(money);
                    Integer pubType = MapUtils.getIntValue(map, "PubType");
                    //1.水费  2.电费  3.燃气
                    switch (pubType) {
                        case 1:
                            dataItem.put("waterMoney", ((BigDecimal) (dataItem.get("waterMoney"))).add(money));
                            break;
                        case 2:
                            dataItem.put("electricity", ((BigDecimal) (dataItem.get("electricity"))).add(money));
                            break;
                        case 3:
                            dataItem.put("gasMoney", ((BigDecimal) (dataItem.get("gasMoney"))).add(money));
                            break;
                    }
                }
                //总合计
                dataItem.put("allSum", allSum);
                //3. 全部放到统一集合中
                resultList.add(dataItem);
            }
        }
        if (page.getSize() < 0) {
            return page.setRecords(resultList);
        }
        //进行分页操作
        page.setTotal(resultList.size());
        if (page.getTotal() <= 0) {
            return page;
        }
        if (page.getTotal() % page.getSize() > 0) {
            page.setPages((page.getTotal() / page.getSize()) + 1);
        } else {
            page.setPages(page.getTotal() / page.getSize());
        }
        List<Map<String, Object>> collect = resultList.stream().skip(((page.getCurrent() - 1) * page.getSize())).limit(page.getSize()).collect(Collectors.toList());
        page.setRecords(collect);
        return page;
    }


//    /**
//     * 导出Excel表格 付款
//     *
//     * @param params
//     */
//    public ModelMap exportIncidentalsForOut(ModelMap modelMap, Map<String, Object> params) {
//        List<Map<String, Object>> dataList = this.getIncidentalsForOut(new Page(1, -1), params).getRecords();
//        String startTime = MapUtils.getString(params, "startTime");
//        String endTime = MapUtils.getString(params, "endTime");
//
//        List<ExcelExportEntity> entityList = new ArrayList<>();
//        //构建表格
//        ExportParams exportParams = new ExportParams(String.format("杂费收款统计 %s~%s", startTime, endTime), "杂费收款", ExcelType.XSSF);
//        exportParams.setStyle(ExcelStyleUtil.class);
//        exportParams.setFixedTitle(true);
//
//        entityList.add(new ExcelExportEntity("收款日期", "BiGenerated"));
//        entityList.add(new ExcelExportEntity("公司", "areaName"));
//        entityList.add(new ExcelExportEntity("服务中心", "centerName"));
//        entityList.add(new ExcelExportEntity("小区名称", "ComName"));
//        entityList.add(new ExcelExportEntity("楼号", "Building"));
//        entityList.add(new ExcelExportEntity("房号", "Room"));
//        entityList.add(new ExcelExportEntity("室号", "room"));
//
//        ExcelExportEntity el = new ExcelExportEntity("电费", "electricity");
//        el.setStatistics(true);
//        entityList.add(el);
//
//        ExcelExportEntity water = new ExcelExportEntity("水费", "waterMoney");
//        water.setStatistics(true);
//        entityList.add(water);
//
//        ExcelExportEntity gas = new ExcelExportEntity("煤气费", "gasMoney");
//        gas.setStatistics(true);
//        entityList.add(gas);
//
//        ExcelExportEntity net = new ExcelExportEntity("网络费", "netMoney");
//        net.setStatistics(true);
//        entityList.add(net);
//
//        ExcelExportEntity allSum = new ExcelExportEntity("收款合计", "allSum");
//        allSum.setStatistics(true);
//        entityList.add(allSum);
//
//        for (ExcelExportEntity entity : entityList) {
//            entity.setWidth(15);
//        }
//
//        modelMap.put(MapExcelConstants.MAP_LIST, dataList);
//        modelMap.put(MapExcelConstants.ENTITY_LIST, entityList);
//        modelMap.put(MapExcelConstants.PARAMS, exportParams);
//        modelMap.put(MapExcelConstants.FILE_NAME, String.format("杂费付款统计报表 (%s~%s)", startTime, endTime));
//        return modelMap;
//    }




    /**
     * 导出Excel表格 付款
     *
     * @param params
     */
    public ModelMap exportIncidentalsForOut(ModelMap modelMap, Map<String, Object> params)throws Exception {


        Map<String,Object> dealMap = this.DateDealwith(params);
        //如果为空那么取当年的数据范围
        params.put("startTime", dealMap.get("StartTime"));
        params.put("endTime", dealMap.get("EndTime"));


        List<Map<String, Object>> dataList = this.getIncidentalsForOutss(params);
        String startTime = MapUtils.getString(params, "startTime");
        String endTime = MapUtils.getString(params, "endTime");

        List<ExcelExportEntity> entityList = new ArrayList<>();
        //构建表格
        ExportParams exportParams = new ExportParams(String.format("杂费收款统计 %s~%s", startTime, endTime), "杂费收款", ExcelType.XSSF);
        exportParams.setStyle(ExcelStyleUtil.class);
        exportParams.setFixedTitle(true);

        //entityList.add(new ExcelExportEntity("收款日期", "BiGenerated"));
        entityList.add(new ExcelExportEntity("公司", "name"));
        entityList.add(new ExcelExportEntity("服务中心", "deptname"));
        entityList.add(new ExcelExportEntity("小区名称", "ComName"));
        entityList.add(new ExcelExportEntity("楼号", "BuilDing"));
        entityList.add(new ExcelExportEntity("房号", "Room"));
        entityList.add(new ExcelExportEntity("房间号", "cod"));
       // entityList.add(new ExcelExportEntity("室号", "room"));
        ExcelExportEntity gys = new ExcelExportEntity("供应商", "gongyingshang");
        gys.setStatistics(true);
        entityList.add(gys);
        ExcelExportEntity tz = new ExcelExportEntity("退租", "tuizu");
        tz.setStatistics(true);
        entityList.add(tz);
        ExcelExportEntity wat = new ExcelExportEntity("水费", "waterMoney");
        wat.setStatistics(true);
        entityList.add(wat);
        ExcelExportEntity ele = new ExcelExportEntity("电费", "eleMoney");
        ele.setStatistics(true);
        entityList.add(ele);
        ExcelExportEntity gas = new ExcelExportEntity("燃气费", "gasMoney");
        gas.setStatistics(true);
        entityList.add(gas);
        ExcelExportEntity net = new ExcelExportEntity("网络费", "kuanMoney");
        net.setStatistics(true);
        entityList.add(net);
        ExcelExportEntity yzw = new ExcelExportEntity("业主违约", "yezhuwei");
        yzw.setStatistics(true);
        entityList.add(yzw);
        ExcelExportEntity allSum = new ExcelExportEntity("收款合计", "allSum");
        allSum.setStatistics(true);
        entityList.add(allSum);
        for (ExcelExportEntity entity : entityList) {
            entity.setWidth(15);
        }

        modelMap.put(MapExcelConstants.MAP_LIST, dataList);
        modelMap.put(MapExcelConstants.ENTITY_LIST, entityList);
        modelMap.put(MapExcelConstants.PARAMS, exportParams);
        modelMap.put(MapExcelConstants.FILE_NAME, String.format("杂费付款统计报表 (%s~%s)", startTime, endTime));
        return modelMap;
    }




































    /**
     * 装修明细报表
     *
     * @param page
     * @param params
     * @return
     */
    public JsonResult getPlanDetailTable(Page page, Map<String, Object> params) {
        params.put("size", page.getSize());
        params.put("current", page.getCurrent());
        return epcFeign.getPlanDetailTable(params);
    }


    /**
     * 导出装修账单表格
     *
     * @param modelMap
     * @param params
     * @return
     */
    public ModelMap exportPlanDetailExcel(ModelMap modelMap, Map<String, Object> params) {
        JsonResult<JSONObject> jsonResult = this.getPlanDetailTable(new Page(1, -1), params);
        if (!jsonResult.isSuccess()) {
            throw new TCException(jsonResult.getErrorMessage());
        }
        Map map = jsonResult.getResult().getJSONArray("records").toJavaList(Map.class).get(0);
        List<Map<String, Object>> col = (List<Map<String, Object>>) map.get("col");
        List<Map<String, Object>> row = (List<Map<String, Object>>) map.get("row");

        List<ExcelExportEntity> entityList = new ArrayList<>();
        //构建表格
        ExportParams exportParams = new ExportParams("装修明细表", "装修明细表", ExcelType.XSSF);
        exportParams.setStyle(ExcelStyleUtil.class);
        exportParams.setFixedTitle(true);

        for (Map<String, Object> colItem : col) {
            ExcelExportEntity entity = new ExcelExportEntity(MapUtils.getString(colItem, "name"), MapUtils.getString(colItem, "key"));
            if (MapUtils.getBooleanValue(colItem, "statistics")) {
                entity.setStatistics(true);
            }

            if(MapUtils.getString(colItem, "key").equals("SumPrice")){
                entity.setStatistics(true);
            }

            entity.setWidth(15);
            int length = MapUtils.getString(colItem, "name").length();
            if (length > 4) {
                entity.setWidth(2.5 * length);
            }
            entityList.add(entity);
        }

        modelMap.put(MapExcelConstants.MAP_LIST, row);
        modelMap.put(MapExcelConstants.ENTITY_LIST, entityList);
        modelMap.put(MapExcelConstants.PARAMS, exportParams);
        modelMap.put(MapExcelConstants.FILE_NAME, "装修明细表");
        return modelMap;
    }

}
